/**
 * Filename: PopListAlbum.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/4/1 17:28
 */
package com.github.postsanf.yinian.activity.pop;

import android.net.Uri;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.ChooseAlbumAdapter;
import com.github.postsanf.yinian.bean.YNAlbum;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.LocalViewHolder;
import com.github.postsanf.yinian.utils.StringUtils;

import java.util.List;

/**
 * 相册发布选择
 */
public class PopListAlbum extends BasePopupWindowForListView<YNAlbum> {
    private ListView mListAlbum;

    public PopListAlbum(int width, int height,
                        List<YNAlbum> datas, View convertView) {
        super(convertView, width, height, true, datas);
    }

    @Override
    public void initViews() {
        mListAlbum = (ListView) findViewById(R.id.lv_album_list_dir);
        mListAlbum.setAdapter(new ChooseAlbumAdapter<YNAlbum>(context, mDatas,
                R.layout.yn_album_list_item) {
            @Override
            public void convert(LocalViewHolder helper, YNAlbum item, Boolean isFirst) {
                helper.setText(R.id.tv_album_choose_item_name, item.getGname());
                Uri uri = Uri.parse(item.getGpic() + StringUtils.getQulity());
                ImageOptHelper.showFrescoNative(uri, (SimpleDraweeView) helper.getView(R.id.iv_album_choose_item_image), mContext);
            }
        });
    }

    public interface OnImageAlbumSelected {
        void selected(YNAlbum item);
    }

    private OnImageAlbumSelected mImageAlbumSelected;

    public void setOnImageAlbumSelected(OnImageAlbumSelected mImageAlbumSelected) {
        this.mImageAlbumSelected = mImageAlbumSelected;
    }

    @Override
    public void initEvents() {
        mListAlbum.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                if (mImageAlbumSelected != null) {
                    mImageAlbumSelected.selected(mDatas.get(position));
                }
            }
        });
    }

    @Override
    public void init() {
    }

    @Override
    protected void beforeInitWeNeedSomeParams(Object... params) {
    }
}
